﻿
using System;
using System.Collections.Generic;
using System.Linq;
using System.Threading.Tasks;
using BCCommon;
using System.Text;
using System.Net;
using Microsoft.AspNetCore.Mvc;
using BCDto.Trading.Purchase.GoodsPurchase;
using BCTMSRESTful.Configs;
using BCService.Utils;
using BCService.Trading.Purchase.GoodsPurchase;
using BCCommon.TradingEnums;

namespace BCTMSRESTful.Controllers.Management.Trading.Purchase
{
    /// <summary>
    /// 商品采购单
    /// </summary>
    [ApiExplorerSettings(GroupName = "AdminTrading")]
    [Route("api/v1/sim/[controller]")]
    public class GoodsPurchaseController : ManagementBaseController
    {
        private readonly IGoodsPurchaseService goodsPurchaseService;

        public GoodsPurchaseController(IGoodsPurchaseService goodsPurchaseService)
        {
            this.goodsPurchaseService = goodsPurchaseService;
        }

        #region 添加商品采购单
        /// <summary>
        ///  添加商品采购单
        /// </summary>
        /// <param name="requestDto">商品采购单信息</param>
        /// <response code="201">添加商品采购单成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost]
        [Log("添加商品采购单")]
        [ProducesResponseType(typeof(GoodsPurchaseDto), 201)]
        public IActionResult Post(
            [FromBody]GoodsPurchaseAllRequestDto requestDto)
        {
            var result = this.goodsPurchaseService.Add(requestDto,this.Admin);
            return StatusCode((int)HttpStatusCode.Created, result);
        }
        #endregion

        #region 修改商品采购单
        /// <summary>
        ///  修改商品采购单
        /// </summary>
        /// <param name="goodsPurchaseId">商品采购单Id</param>
        /// <param name="requestDto">商品采购单信息</param>
        /// <response code="200">修改商品采购单成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{goods_purchase_id}")]
        [Log("修改商品采购单")]
        [ProducesResponseType(typeof(GoodsPurchaseDto), 200)]
        public IActionResult Put([FromRoute(Name = "goods_purchase_id")]long goodsPurchaseId, [FromBody]GoodsPurchaseRequestDto requestDto)
        {
            GoodsPurchasePutDto putDto = requestDto.As<GoodsPurchasePutDto>();
            putDto.GoodsPurchaseId = goodsPurchaseId;
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.Update(putDto,this.Admin));
        }
        #endregion

        #region 删除商品采购单
        /// <summary>
        ///  删除商品采购单
        /// </summary>
        /// <param name="goodsPurchaseId">商品采购单Id</param>
        /// <response code="204">删除商品采购单成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpDelete("{goods_purchase_id}")]
        [Log("删除商品采购单")]
        [ProducesResponseType(typeof(NoContentResult), 204)]
        public IActionResult Delete([FromRoute(Name = "goods_purchase_id")]long goodsPurchaseId)
        {
            this.goodsPurchaseService.Delete(goodsPurchaseId);
            return StatusCode((int)HttpStatusCode.NoContent);
        }
        #endregion

        #region 获取商品采购单
        /// <summary>
        ///  获取商品采购单
        /// </summary>
        /// <param name="goodsPurchaseId">商品采购单Id</param>
        /// <response code="200">获取商品采购单</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("{goods_purchase_id}")]
        [ProducesResponseType(typeof(GoodsPurchaseDto), 200)]
        public IActionResult Get([FromRoute(Name = "goods_purchase_id")]long goodsPurchaseId)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.Get(goodsPurchaseId));
        }
        #endregion

        #region 获取商品采购单（分页）
        /// <summary>
        ///  获取商品采购单（分页）
        /// </summary>
        /// <param name="purchaseNo">采购单编号</param>
        /// <param name="purchaseInventoryStatusType">采购库存状态类型</param>
        /// <param name="purchaseDateType">采购日期类型</param>
        /// <param name="start">开始时间</param>
        /// <param name="end">结束时间</param>
        /// <param name="sortName">排序字段</param>
        /// <param name="ascending">升序</param>
        /// <param name="index">当前页码</param>
        /// <param name="size">当前页大小</param>
        /// <response code="200">获取商品采购单（分页）</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpGet("[action]")]
        [ProducesResponseType(typeof(PageableList<GoodsPurchaseDto>), 200)]
        public IActionResult Query(
            [FromQuery(Name = "purchase_no")]string purchaseNo,
            [FromQuery(Name = "inventory_status")]PurchaseInventoryStatusType? purchaseInventoryStatusType,
            [FromQuery(Name = "purchase_date_type")]PurchaseDateType? purchaseDateType,
            [FromQuery(Name = "start")]DateTime? start,
            [FromQuery(Name = "end")]DateTime? end,
            [FromQuery(Name = "sort_name")]string sortName,
            [FromQuery(Name = "ascending")]bool? ascending,
            [FromQuery(Name = "index")]int index = 1,
            [FromQuery(Name = "size")]int size = 10)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.Query(purchaseNo, purchaseInventoryStatusType, purchaseDateType, start, end, sortName, ascending, index, size));
        }
        #endregion

        #region 修改商品采购单状态
        /// <summary>
        ///  修改商品采购单状态
        /// </summary>
        /// <param name="goodsPurchaseId">商品采购单Id</param>
        /// <param name="purchaseStatusType">商品采购单状态</param>
        /// <response code="200">修改商品采购单状态成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPut("{goods_purchase_id}/Status/{purchase_status_type}")]
        [Log("修改商品采购单状态")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult UpdatePurchaseStatus([FromRoute(Name = "goods_purchase_id")]long goodsPurchaseId,
            [FromRoute(Name = "purchase_status_type")]PurchaseStatusType purchaseStatusType)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.UpdatePurchaseStatus(goodsPurchaseId,purchaseStatusType));
        }
        #endregion

        #region 录入商品采购单定金支付信息
        /// <summary>
        ///  录入商品采购单定金支付信息
        /// </summary>
        /// <param name="requestDto">商品采购单定金支付信息</param>
        /// <response code="200">录入商品采购单定金支付信息成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost("DepositePaid")]
        [Log("录入商品采购单定金支付信息")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult SettingDepositePaidInfo([FromBody]GoodsPurchaseDepositePaymentRequestDto requestDto)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.UpdateDepositePaymentInfo(requestDto));
        }
        #endregion

        #region 录入商品采购单尾款支付信息
        /// <summary>
        ///  录入商品采购单尾款支付信息
        /// </summary>
        /// <param name="requestDto">商品采购单尾款支付信息</param>
        /// <response code="200">录入商品采购单尾款支付信息成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost("LastPaid")]
        [Log("录入商品采购单尾款支付信息")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult SettingLastPaidInfo([FromBody]GoodsPurchaseLastPaymentRequestDto requestDto)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.UpdateLastPaymentInfo(requestDto));
        }
        #endregion

        #region 设置商品采购单交付信息
        /// <summary>
        ///  设置商品采购单交付信息
        /// </summary>
        /// <param name="requestDto">商品采购单交付信息</param>
        /// <response code="200">设置商品采购单交付信息成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost("DeliveryInfo")]
        [Log("设置商品采购单交付信息")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult SettingDeliveryInfo([FromBody]GoodsPurchaseDeliveryInfoRequestDto requestDto)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.UpdateDeliveryInfo(requestDto,this.Admin));
        }
        #endregion

        #region 修改商品采购单暂停状态
        /// <summary>
        ///  修改商品采购单暂停状态
        /// </summary>
        /// <param name="requestDto">商品采购单备注信息</param>
        /// <response code="200">修改商品采购单暂停状态成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost("Suspend")]
        [Log("修改商品采购单暂停状态")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult UpdateSuspendStatus([FromBody]GoodsPurchaseRemarkRequestDto requestDto)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.UpdateSuspendRemark(requestDto));
        }
        #endregion

        #region 修改商品采购单恢复状态
        /// <summary>
        ///  修改商品采购单恢复状态
        /// </summary>
        /// <param name="requestDto">商品采购单备注信息</param>
        /// <response code="200">修改商品采购单恢复状态成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost("Restore")]
        [Log("修改商品采购单恢复状态")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult UpdateRestoreStatus([FromBody]GoodsPurchaseRemarkRequestDto requestDto)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.UpdateRestoreRemark(requestDto));
        }
        #endregion

        #region 修改商品采购单终止状态
        /// <summary>
        ///  修改商品采购单终止状态
        /// </summary>
        /// <param name="requestDto">商品采购单备注信息</param>
        /// <response code="200">修改商品采购单终止状态成功</response>
        /// <response code="400">请求参数或输入的数据不正确。</response>
        /// <response code="500">服务器发生错误。</response>
        /// <response code="501">某些功能尚未实现。</response>
        /// <returns></returns>
        [HttpPost("Stop")]
        [Log("修改商品采购单终止状态")]
        [ProducesResponseType(typeof(bool), 200)]
        public IActionResult UpdateStopStatus([FromBody]GoodsPurchaseRemarkRequestDto requestDto)
        {
            return StatusCode((int)HttpStatusCode.OK, this.goodsPurchaseService.UpdateStopRemark(requestDto));
        }
        #endregion
    }
}

